<template>
	<view class="content">
		<u-navbar title="商品详情" :placeholder="true" left-icon-size="32rpx" bg-color="#FF594D" :autoBack="false"
			titleStyle="color:#fff;font-size:32rpx" height="88rpx" leftIconColor="#fff" @leftClick="leftClick">
		</u-navbar>

		<view class="swiper_content">
			<u-swiper height="750rpx" :list="list" @change="e => current = e.current" :autoplay="false">
				<view slot="indicator" class="indicator">
					<view class="indicator__dot" v-for="(item, index) in list" :key="index"
						:class="[index === current && 'indicator__dot--active']">
					</view>
				</view>
			</u-swiper>
			<view class="share">
				<button @click="shareButtonShow = true">

					<image src="../static/images/detail-page/Group 8@2x.png" mode=""></image>
				</button>
			</view>
			<!-- 	<view class="buy_list">
				<template v-for="(item,index) in buy">
					<view class="buy_item" :key="index">
						{{item.user}}购买了此商品
					</view>
				</template>
			</view> -->
		</view>
		<u-popup :show="shareShow" :safeAreaInsetBottom="false" @close="close" mode="center" @open="open">
			<view class="canvasItem">
				<image mode="widthFix" style="width:600rpx;height:500rpx" :src="canvasImg"></image>
			</view>
			<view class="saveImage">
				<view class="saveBtn" @click="onSaveImg">
					保存海报
				</view>
			</view>
		</u-popup>
		<u-popup :show="shareButtonShow" @close="shareClose" mode="bottom" @open="shareOpen">
			<view class="shareButton">
				<view class="shareItem" @click="shareButtonShow = false;shareShow=true">
					<u-icon name="grid" color="#000000" size="200rpx"></u-icon>
					<text>一物一码</text>
				</view>
				<button class="shareItem" open-type="share" @click="shareButtonShow = false">
					<u-icon name="weixin-fill" color="#6ECE46" size="200rpx"></u-icon>
					<text>分享给朋友</text>
				</button>
			</view>
		</u-popup>
		<view class="goods_price">
			<view class="price_top">
				<view class="left">
					<view class="current_price">
						<text>￥</text>{{goodsInfo.list[0].specificationPrice.toFixed(2)}}
					</view>
					<view class="original_price">
						<text>{{goodsInfo.list[0].priceOriginally.toFixed(2)}}￥</text>
					</view>
				</view>
				<view class="tags">
					<!-- 	<view class="tag_item">
						全场优惠券
					</view> -->
					<view class="tag_item">
						7天无忧快速退货
					</view>
					<!-- <view class="tag_item">
						满10元免邮费
					</view> -->
				</view>
			</view>
			<view class="goods_title">
				{{goodsInfo.commodityName}}
			</view>
		</view>
		<!-- <search-button-input ref="card"></search-button-input> -->
		<view class="goods_num" v-if="commodityType!=1">
			<view class="goods_num_content">
				<view class="goods_img">
					<image :src="goodsInfo.image" mode=""></image>
				</view>
				<view class="adjustment">
					<view class="price">
						<text>{{commodityType==2?'团购':''}}价格：</text>￥{{(goodsInfo.list[0].specificationPrice*goodsNum).toFixed(2)}}
					</view>
					<view class="adjustment_num" v-if="commodityType!=2">
						<button @click="reduce">-</button>
						<input v-model="goodsNum" @blur="goodsVerify" type="number" />
						<button @click="increase">+</button>
					</view>
					<view class="adjustment_num"
						style="white-space: nowrap;                                                                         "
						v-else>
						团购人数：<text>{{goodsInfo.buyNumber}}人</text>
					</view>
				</view>
			</view>
		</view>
		<!-- <image :src="src" mode=""></image> -->
		<!-- <view class="titleBtn" @click="createGoodsPoster">绘制海报</view> -->
		<!-- 	<view class="canvasBox" v-if="canvasImg">
			<view class="canvasItem">
				<image mode="widthFix" style="width:500rpx;height:500rpx" :src="canvasImg"></image>
			</view>
			<view class="button" @click="onSaveImg">保存海报</view>
		</view> -->
		<view class="canvas_content" style="position: fixed;top:-99999999999px;">
			<canvas class="f__canvas" style="width:1200px;height:1700px" canvas-id="firstCanvas" id="firstCanvas"></canvas>
		</view>
		<!-- <canvas canvas-id="canvas" id="canvas"></canvas> -->
		<view class="tab">
			<view @click="change(0)" :class="['tab-item',tabIndex ==0?'active':'']">
				<text>商品详情</text>
			</view>
			<view @click="change(1)" :class="['tab-item',tabIndex ==1?'active':'']">
				<text>商品评价</text>
			</view>
		</view>

		<view class="goods_detail_img" v-if="tabIndex==0&&goodsInfo.description">
			<view class="specification">
				商品描述
			</view>
			<view class="description">
				<u-parse :content="goodsInfo.description" :tagStyle="descriptionStyle"></u-parse>
			</view>

		</view>
		<view class="comment_content" v-else>
			<view class="specification">
				商品评价
			</view>
			<view class="goods_evaluate" v-if="goodsComment[0]">
				<!-- 				<view class="evaluate_title2">
					评价
				</view> -->
				<template v-for="(commen,index) in goodsComment">
					<view class="comment_item" :key="index">
						<view class="line">
							<u-line></u-line>
						</view>
						<view class="">
							<view class="user_info">
								<view class="user_hade">
									<image :src="commen.avatar"></image>
								</view>
								<view class="evaluate_status">
									<view class="status_left">
										评价时间：{{commen.createTime}}
									</view>
									<view class="">
										图片信息：
									</view>
								</view>
							</view>
							<view class="evaluate_image">
								<view class="evaluate_image_content">
									<template v-for="(item,index) in commen.commodityName.split(',')">
										<view class="image_item" :key="index">
											<image :src="item" mode=""></image>
										</view>
									</template>
								</view>
							</view>
							<view class="evaluate_status">
								<view class="status_left">
									内容信息：{{commen.content}}
								</view>
							</view>

						</view>
					</view>
				</template>
			</view>
		</view>
		<view class="goods_nav" v-if="commodityType!=2 && commodityType!=1">
			<uni-goods-nav :fill="true" :options="options" :button-group="customButtonGroup" @click="onClick"
				@buttonClick="buttonClick" style="margin-top: 20px;" />
		</view>
		<view class="sponsor" v-if="commodityType==2">
			<view class="sponsor_btn" @click="sponsorGroun">
				发起拼团
			</view>
		</view>
		<!-- <image src="../static/images/detail-page/gh_14cf42d05960_430.jpg" mode=""></image> -->
		<view class="sponsor" v-if="commodityType==1">
			<view class="sponsor_btn" @click="seckillBuy">
				立即抢购
			</view>
		</view>
	</view>
</template>

<script>
	import baseUrl from '../../utils/base.js'
	import _canvas from '@/uni_modules/fan-canvas/canvasUtils'; // 加载万能绘制方法
	import {
		saveImg,
		qrcodeCanvas
	} from '@/uni_modules/fan-canvas/plugins/utils'; // 需要保存图片和生成二维码可以引用此文件
	import {
		getCommodityInfo,
		addBuy,
		goodsCommens
	} from '../../api/index.js'
	import {
		addCart,
		getCart
	} from '../../api/shopCar.js'
	import {
		addCollection,
		getCollection,
		delCollect
	} from '../../api/mine.js'
	import {
		wxacodeunlimit
	} from '../../api/seckill.js'
	import image from '../../uni_modules/uview-ui/libs/config/props/image.js';
	export default {
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				// console.log(res.target)
			}
			return {
				title: this.goodsInfo.commodityName,
				imageUrl: this.goodsInfo.image
			}
		},
		onReady() {

		},
		onLoad(option) {

			uni.$on('colsepri', () => {
				this.close()
			})
			this.pageArr = getCurrentPages();
			// console.log(arr);
			if (option.scene) {

				// console.log(decodeURIComponent(option.scene));
				const scene = decodeURIComponent(option.scene)
				const query = this.urlParamsToObject(scene)
				this.goodsId = query.id
				if (query.employeeId) {
					this.employeeId = query.employeeId
				}
				// const query = scene.replaceAll('(', '{').replaceAll(')', '}')
				console.log(query);
			}
			if (option.id) {
				this.goodsId = option.id
			}
			this.getCommodityInfoData(this.goodsId)
			if (option.commodityType == 2) {
				this.commodityType = option.commodityType
			}
			if (option.commodityType == 1) {
				this.commodityType = option.commodityType
			}

		},
		onShow() {
			this.$store.commit('setCouponId', 0)
			this.$store.commit('setAddressId', 0)
		},
		data() {
			return {
				draw: null,
				shareShow: false,
				shareButtonShow: false,
				list: [
					// 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
					// 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
					// 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
				],
				titleStyle: {
					color: '#fff',
				},
				descriptionStyle: {
					img: 'width:750rpx',

				},
				goodsNum: 1,
				current: 0,
				pageArr: [],
				buy: [{
					user: "梁**"
				}, {
					user: "祝**"
				}, {
					user: "冯**"
				}],
				options: [{
					icon: '/pages_goods/static/images/detail-page/Frame@2x.png',
					text: '首页'
				}, {
					icon: '/pages_goods/static/images/detail-page/爱心.png',
					text: '收藏',
				}, {
					icon: '/pages_goods/static/images/detail-page/Frame@2x (1).png',
					text: '购物车',
					info: 0
				}],
				customButtonGroup: [{
						text: '加入购物车',
						backgroundColor: '#FFA242',
						color: '#fff',
						width: "100rpx"
					},
					{
						text: '立即购买',
						backgroundColor: '#FF594D',
						color: '#fff',
					}
				],
				src: '',
				goodsInfo: {
					list: [{
						specificationPrice: 1,
						priceOriginally: 1
					}]
				},
				goodsId: '',
				employeeId: '', // 员工id
				goods: {},
				commodityType: null,
				tabIndex: 0,
				goodsComment: [],
				buttonImg: '', //按钮
				canvasImg: '', //生成的海报图片
				qrcodeImg: '', //二维码本地图片
				content: '', //内容
				textImg: '', //文本超出省略
				content2: "",
				textEnImg: '', //英文
			}
		},
		created() {
			if (!this.$store.getters.getIsLogin) {
				this.getCartData()
				return
			}
			// this.createDraw()
		},
		mounted() {
			// this.createGoodsPoster()
		},
		methods: {
			open() {
				// console.log('open');
				this.createGoodsPoster()
			},
			close() {

				this.shareShow = false
				// console.log('close');
			},
			shareOpen() {
				// console.log('open');
				// this.createGoodsPoster()
			},
			shareClose() {
				this.shareButtonShow = false
			},
			urlParamsToObject(url) {
				//获取字符串 ? 后面的部分
				const queryString = url.split('?')[1];
				const paramsArr = queryString.split('&');
				const paramObj = {};

				paramsArr.forEach(param => {
					const [key, value] = param.split('=');
					paramObj[key] = decodeURIComponent(value);
				});

				return paramObj;
			},
			async createGoodsPoster() {
				// console.log(this.canvasImg);
				const that = this
				const pages = getCurrentPages() // 获取栈实例
				console.log(pages);

				const currentPage = pages[pages.length - 1]['route'] //当前页面路径(带参数)
				uni.showLoading({
					title: '分享海报生成中'
				});
				let sceneStr = `https://?id=${this.goodsId}`
				if (this.$store.state.user.isSysuserid) {
					sceneStr = `https://?id=${this.goodsId}&employeeId=${this.$store.state.user.isSysuserid}`
				}
				if (this.$store.state.member.employeeId) {
					sceneStr = `https://?id=${this.goodsId}&employeeId=${this.$store.state.member.employeeId}`
				}

				// 获取微信小程序码
				const res = await wxacodeunlimit({
					page: currentPage,
					sceneStr
				})
				if (res.code == 200) {
					let uint8Array = new Uint8Array(res.data);
					const base64 = uni.arrayBufferToBase64(uint8Array)
					// console.log(base64);
					// that.src = 'data:image/jpeg;base64,' + base64
					// var urlQR = await await poster.base64ToSave(that.src);
					that.src = res.data
					// 删除保存到本地的小程序码
					const removeSave = function(FILE_BASE_NAME = 'tmp_base64src', format = 'jpeg') {
						return new Promise((resolve) => {
							// 把文件删除后再写进，防止超过最大范围而无法写入
							const fsm = uni.getFileSystemManager(); //文件管理器
							const FILE_BASE_NAME = 'tmp_base64src';
							const format = 'jpeg';
							const filePath = `${wx.env.USER_DATA_PATH}/${FILE_BASE_NAME}.${format}`;
							fsm.unlink({
								filePath: filePath,
								success(res) {
									console.log('文件删除成功');
								},
								fail(e) {
									console.log('readdir文件删除失败：', e)
								}
							});
						})
					}
					//base64转本地图片，将数据存储在本地
					const base64ToSave = function(base64data, FILE_BASE_NAME = 'tmp_base64src') {
						const fsm = uni.getFileSystemManager();
						return new Promise((resolve, reject) => {
							//format这个跟base64数据的开头对应
							const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(
								base64data) || [];
							if (!format) {
								reject(new Error('ERROR_BASE64SRC_PARSE'));
							}
							const filePath = `${wx.env.USER_DATA_PATH}/${FILE_BASE_NAME}.${format}`;
							const buffer = wx.base64ToArrayBuffer(bodyData);
							fsm.writeFile({
								filePath,
								data: buffer,
								encoding: 'binary',
								success() {
									console.log(filePath);
									that.src = filePath
									resolve(filePath);
								},
								fail() {
									reject(new Error('ERROR_BASE64SRC_WRITE'));
								},
							});
						});
					}
					base64ToSave(that.src).then(async () => {
						if (that.canvasImg) {
							return
						}
						// var that = that;

						const cvsW = 1200;
						const cvsH = 1700;
						const goodsH = 660;
						const logo_w = 100;
						const margin = 30;
						// let family = "";
						let family =
							" 'PingFang SC',tahoma,arial,'helvetica neue','hiragino sans gb','microsoft yahei',sans-serif";
						let ctx = uni.createCanvasContext('firstCanvas');

						// 绘制矩形
						_canvas.fillRoundRect(ctx, 0, 0, cvsW, cvsH, 0, "#ffffff");
						// _canvas.fillRoundRect(ctx, 30, 30, cvsW - 60, cvsH - 60, 20, "#eee");

						// 同步加载图片
						var logo = await _canvas.getImageInfo(that.goodsInfo.image);
						var mapCode = await _canvas.getImageInfo(that.src);


						if (logo.path && mapCode.path) {
							ctx.save();
							ctx.clip();
							ctx.beginPath()
							ctx.setShadow(0, 0, 30, '#999');
							_canvas.fillRoundRect(ctx, 30, 30, cvsW - 60, cvsH - 60, 20, "#fff");
							ctx.closePath();

							ctx.strokeStyle = `#8FAB31`;
							ctx.strokeRect(73, 73, 1051, 1051);
							ctx.strokeStyle = `#8FAB31`;
							ctx.strokeRect(74, 74, 1050, 1050);

							// 绘制小程序码
							ctx.shadowBlur = 0
							ctx.setShadow(0, 0, 0, '#999');
							_canvas.drawImgCover(ctx, mapCode, 678, 1176, 430, 430);
							// ctx.drawImage(mapCode.path, 671, 1161, 460, 460)
							ctx.restore();

							// 绘制商品图片
							_canvas.drawImgCover(ctx, logo, 106, 106, 985, 985);
							ctx.restore();
							// ctx.font = "46px" + family
							// ctx.fillText('39.99', 50, 450)

							// 现价
							ctx.setFillStyle('#171717')
							ctx.font = "34rpx" + family
							ctx.fillText('现价', 106, 1200)

							// 价格符号
							ctx.setFillStyle('#ff0036')
							ctx.font = "30rpx" + family
							ctx.fillText('￥', 196, 1203)

							// 价格
							ctx.font = "46px" + family
							ctx.fillText(that.goodsInfo.list[0].specificationPrice.toFixed(2), 226, 1203)

							// 原价
							ctx.setFillStyle('#171717')
							ctx.font = "34rpx" + family
							ctx.fillText('原价: ' + that.goodsInfo.list[0].priceOriginally.toFixed(2), 400,
								1200)

							ctx.setFillStyle('#000000')
							ctx.textAlign = 'left';
							var options = {
								font: "normal 36px" + family, //设置字体
								ctx: ctx,
								word: that.goodsInfo.commodityName, //文本
								maxWidth: 500, //最大宽度
								maxLine: 1, //最大行数--超出省略
								x: 106, //x坐标
								y: 1300, //y坐标
								l_h: 40 //行高
							}
							// 文本自定义换行
							_canvas.dealWords(options)

							// 商品线段
							ctx.beginPath(); //新建一条path
							ctx.moveTo(88, 1360); //把画笔移动到指定的坐标
							ctx.lineTo(600, 1360); //绘制一条从当前位置到指定坐标(200, 50)的直线.
							//闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合，则什么都不做
							ctx.closePath();
							ctx.strokeStyle = `#8DA34A`;
							ctx.stroke(); //绘制路径。

							// 臻选择
							ctx.setFillStyle('#FFD522')
							ctx.font = "50rpx italic" + family
							ctx.fillText('臻 选 择', 220, 1420)


							// 小程序码线段
							ctx.beginPath(); //新建一条path
							ctx.moveTo(662, 1160); //把画笔移动到指定的坐标
							ctx.lineTo(732, 1160); //绘制一条从当前位置到指定坐标(200, 50)的直线.
							ctx.strokeStyle = `#8DA34A`;
							ctx.stroke(); //绘制路径。

							ctx.beginPath(); //新建一条path
							ctx.moveTo(662, 1160); //把画笔移动到指定的坐标
							ctx.lineTo(662, 1230); //绘制一条从当前位置到指定坐标(200, 50)的直线.
							ctx.strokeStyle = `#8DA34A`;
							ctx.stroke(); //绘制路径。

							ctx.beginPath(); //新建一条path
							ctx.moveTo(1123, 1160); //把画笔移动到指定的坐标
							ctx.lineTo(1053, 1160); //绘制一条从当前位置到指定坐标(200, 50)的直线.
							ctx.strokeStyle = `#8DA34A`;
							ctx.stroke(); //绘制路径。

							ctx.beginPath(); //新建一条path
							ctx.moveTo(1123, 1160); //把画笔移动到指定的坐标
							ctx.lineTo(1123, 1230); //绘制一条从当前位置到指定坐标(200, 50)的直线.
							ctx.strokeStyle = `#8DA34A`;
							ctx.stroke(); //绘制路径。

							// 小程序码线段
							ctx.beginPath(); //新建一条path
							ctx.moveTo(662, 1621); //把画笔移动到指定的坐标
							ctx.lineTo(732, 1621); //绘制一条从当前位置到指定坐标(200, 50)的直线.
							ctx.strokeStyle = `#8DA34A`;
							ctx.stroke(); //绘制路径。

							ctx.beginPath(); //新建一条path
							ctx.moveTo(662, 1621); //把画笔移动到指定的坐标
							ctx.lineTo(662, 1551); //绘制一条从当前位置到指定坐标(200, 50)的直线.
							ctx.strokeStyle = `#8DA34A`;
							ctx.stroke(); //绘制路径。

							ctx.beginPath(); //新建一条path
							ctx.moveTo(1123, 1621); //把画笔移动到指定的坐标
							ctx.lineTo(1053, 1621); //绘制一条从当前位置到指定坐标(200, 50)的直线.
							ctx.strokeStyle = `#8DA34A`;
							ctx.stroke(); //绘制路径。

							ctx.beginPath(); //新建一条path
							ctx.moveTo(1123, 1621); //把画笔移动到指定的坐标
							ctx.lineTo(1123, 1551); //绘制一条从当前位置到指定坐标(200, 50)的直线.
							ctx.strokeStyle = `#8DA34A`;
							ctx.stroke(); //绘制路径。
							// 长按识别小程序码
							ctx.setFillStyle('#8DAD2D')
							ctx.font = "34rpx" + family
							ctx.fillText('长按识别小程序码', 762, 1635)

							ctx.draw(false, () => {}, 500)
							const timer = setTimeout(() => {
								uni.canvasToTempFilePath({
									width: cvsW,
									height: cvsH,
									canvasId: 'firstCanvas',
									success(res) {

										uni.hideLoading();
										that.canvasImg = res.tempFilePath
										removeSave(that.src)

									},
									fail(err) {
										uni.hideLoading();
										// console.log(err);
									}
								}, that)
							}, 500)
						} else {
							uni.hideLoading();
							uni.showToast({
								title: '海报制作失败',
								icon: 'none'
							});
						}
					})
					// console.log(image);
					return
				}
				uni.hideLoading()
				uni.showToast({
					title: '生成失败',
					icon: 'error'

				})
				// if (res.code == 401) {
				// 	uni.showToast({
				// 		title: '请先登录',
				// 		icon: 'error'

				// 	})
				// }
				this.shareShow = false
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: baseUrl + '/common/uploadOss',
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							resolve(JSON.parse(res.data).msg)
						}
					});
				})
			},
			// 保存图片
			async onSaveImg() {
				let imgUrl = "";
				uni.showLoading({
					title: '正在下载'
				});
				if (this.canvasImg) {
					imgUrl = await this.canvasImg;
					console.log(imgUrl);
					const res = await this.uploadFilePromise(imgUrl)
					// console.log(res);

					saveImg(res)
				}
			},

			// 获取单个商品信息
			async getCommodityInfoData(id) {
				const res = await getCommodityInfo(id)
				console.log(res);
				this.goodsInfo = res.data
				this.list = res.data.carousel.split(',')
				this.getGoodsCommens(this.goodsInfo.id)
			},
			async getCartData() {
				if (!this.$store.getters.getIsLogin) {
					return
				}
				const res = await getCart()
				this.options[2].info = res.total
			},
			change(index) {
				this.tabIndex = index
			},
			leftClick() {
				// console.log(this.pageArr);
				if (this.pageArr.length >= 2) {
					uni.navigateBack()
					return
				}
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			async onClick({
				index,
				content
			}) {
				switch (index) {
					case 0:
						uni.switchTab({
							url: '/pages/index/index'
						})
						break;
						// 收藏
					case 1:
						if (!this.$store.getters.getIsLogin) {
							uni.navigateTo({
								url: '/pages_mine/pages/login/login'
							})
							return
						}
						const collet = await getCollection()
						this.collectionData = collet.rows
						// console.log(this.collectionData)
						let colletFlag = false
						let collectIndex = 0
						this.collectionData.forEach((item, index) => {
							if (item.commodityId == this.goodsInfo.id) {
								colletFlag = true
								collectIndex = index
							}
						})
						// console.log(colletFlag, collectIndex)
						if (colletFlag) {
							const delCollet = await delCollect(this.collectionData[collectIndex].id)
							uni.showToast({
								title: '已取消收藏',
								icon: 'error',
								success: () => {
									this.options[1].icon = '/pages_goods/static/images/detail-page/爱心.png'
								}
							})
							return
						}
						const res = await addCollection({
							userld: this.$store.state.userInfo.id,
							commodityId: this.goodsInfo.id,
							image: this.goodsInfo.image,
							commodityName: this.goodsInfo.commodityName,
							specificationId: this.goodsInfo.list[0].id,
							specificationName: this.goodsInfo.list[0].specificationName,
							specificationPrice: this.goodsInfo.list[0].specificationPrice,
							specificationNumber: 1
						})
						// console.log(res)
						uni.showToast({
							title: '已收藏',
							success: () => {
								this.options[1].icon = '/pages_goods/static/images/detail-page/爱心@2x.png'
							}
						})
						break
					case 2:
						if (!this.$store.getters.getIsLogin) {
							uni.navigateTo({
								url: '/pages_mine/pages/login/login'
							})
							return
						}
						uni.switchTab({
							url: '/pages/shopCar/shopCar'
						})
						this.$store.commit('setTabValue', 3)
						break
				}
			},

			async buttonClick({
				index,
				content
			}) {
				if (!this.$store.getters.getIsLogin) {
					uni.navigateTo({
						url: '/pages_mine/pages/login/login'
					})
					return
				}
				switch (index) {
					case 0:
						// console.log(this.goodsInfo)
						if (this.goodsNum > this.goodsInfo.inventory) {
							uni.showToast({
								title: '库存不足',
								icon: 'error'
							})
							return
						}
						let code = 0
						for (let i = 1; i <= this.goodsNum; i++) {
							const res = await addCart({
								userld: this.$store.state.userInfo.id,
								commodityId: this.goodsInfo.id,
								image: this.goodsInfo.image,
								name: this.goodsInfo.commodityName,
								specificationId: this.goodsInfo.list[0].id,
								specificationName: this.goodsInfo.list[0].specificationName,
								specificationAmount: this.goodsInfo.list[0].specificationPrice,
								specificationNumber: 1
							})
							// console.log(res)
							code = res.code
						}

						if (code != 200) {
							uni.showToast({
								title: '加入购物车失败',
								icon: "error"
							})
							return
						}
						this.getCartData()
						uni.showToast({
							title: '加入购物车成功'
						})

						break;
					case 1:
						if (this.goodsNum > this.goodsInfo.inventory) {
							uni.showToast({
								title: '库存不足',
								icon: 'error'
							})
							return
						}
						if (this.employeeId) {
							uni.navigateTo({
								url: `/pages_mine/pages/order-form/order-form?id=${this.goodsInfo.id}&number=${this.goodsNum}&employeeId=${this.employeeId}`
							})
							return
						}
						uni.navigateTo({
							url: `/pages_mine/pages/order-form/order-form?id=${this.goodsInfo.id}&number=${this.goodsNum}`
						})
						break;
				}
			},
			increase() {
				if (this.goodsNum >= this.goodsInfo.inventory) {
					uni.showToast({
						title: '库存不足',
						icon: 'error'
					})
					return
				}
				this.goodsNum++
			},
			reduce() {
				if (this.goodsNum <= 1) return
				this.goodsNum--
			},
			goodsVerify() {
				// console.log(1);
				if (this.goodsNum < 1) {
					// console.log(this.goodsNum);
					this.goodsNum = 1
				}
			},
			async sponsorGroun() {
				if (!this.$store.getters.getIsLogin) {
					uni.navigateTo({
						url: '/pages_mine/pages/login/login'
					})
					return
				}
				const res = await addBuy({
					createBy: this.$store.state.userInfo.id,
					sponsorId: this.$store.state.userInfo.id,
					commodityId: this.goodsInfo.id,
					commodityName: this.goodsInfo.commodityName,
					image: this.goodsInfo.image,
					specificationName: this.goodsInfo.list[0].specificationName,
					specificationId: this.goodsInfo.list[0].id,
					specificationPrice: this.goodsInfo.list[0].specificationPrice,
					specificationNumber: 1,
					xxx: this.$store.state.user.name
				})
				// console.log(res);
				if (res.code == 200) {

					uni.navigateTo({
						url: `/pages_mine/pages/order-form/order-form?id=${this.goodsInfo.id}&number=1&buyNumber=${res.data.buyNumber}`
					})
				}
			},
			seckillBuy() {
				if (!this.$store.getters.getIsLogin) {
					uni.navigateTo({
						url: '/pages_mine/pages/login/login'
					})
					return
				}
				if (1 > this.goodsInfo.inventory) {
					uni.showToast({
						title: '库存不足',
						icon: 'error'
					})
					return
				}
				uni.navigateTo({
					url: `/pages_mine/pages/order-form/order-form?id=${this.goodsInfo.id}&number=${1}`
				})
			},
			async getGoodsCommens(id) {
				const res = await goodsCommens(id)
				// console.log(res);
				this.goodsComment = res.rows

			}
		}
	}
</script>

<style lang="scss">
	.content {
		background-color: #f3f3f3;
		min-height: 100vh;
		padding-bottom: 150rpx;
		overflow-x: hidden;
	}

	.shareButton {
		display: flex;
		height: 375rpx;

		.shareItem {
			display: flex;
			align-items: center;
			flex-direction: column;
			justify-content: center;
			width: 375rpx;
		}

		button {
			background-color: transparent;
			padding: 0;
			border-radius: 0;

			&::after {
				border: 0;

			}
		}
	}

	.saveImage {
		padding: 15rpx 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;

		.saveBtn {
			border-radius: 999rpx;
			width: 400rpx;
			height: 50rpx;
			background-color: #FF594D;
			// text-align: center;
			font-size: 30rpx;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;

		}
	}

	.description {
		// padding: 20rpx 0;
		background-color: #fff;
	}

	.goods_evaluate {
		background-color: #fff;
		padding: 24rpx 20rpx;
		margin-top: 20rpx;

		.evaluate_title2 {
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #D54939;
		}

		.user_info {
			height: 80rpx;
			padding: 20rpx 0;
			display: flex;


			.user_hade {
				width: 80rpx;
				height: 80rpx;
				border-radius: 99rpx;
				overflow: hidden;
				margin-right: 20rpx;

				image {
					width: 80rpx;
					height: 80rpx;
				}
			}

			.user_right {
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.username {
					font-size: 26rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 800;
					color: #000000;
				}

				.time {
					font-size: 24rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #777777;
				}
			}

			.evaluate_status {
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #777777;

				.line {
					padding: 24rpx 0;
				}

				.status_left {
					padding-bottom: 10rpx;
				}
			}
		}

		.evaluate_status {
			font-size: 24rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #777777;

			.line {
				padding: 24rpx 0;
			}

			.status_left {
				padding-bottom: 10rpx;
			}
		}

		.evaluate_image {
			.evaluate_image_content {
				display: flex;
				padding: 24rpx 20rpx;
				flex-wrap: wrap;

				.image_item {
					width: 140rpx;
					height: 140rpx;
					margin-right: 30rpx;
					margin-bottom: 24rpx;

					image {
						width: 140rpx;
						height: 140rpx;

					}
				}

				.image_item:nth-of-type(4n+0) {
					margin-right: 0;
				}
			}
		}
	}

	.tab {
		display: flex;
		background-color: #fff;
		// margin-bottom: 20rpx;

		.tab-item {
			// width: 375rpx;
			flex: 1;
			height: 80rpx;
			text-align: center;
			line-height: 80rpx;
			position: relative;
			color: #333332;
			font-size: 26rpx;

			text {
				display: inline-block;
				width: 100%;
			}

			&.active {
				color: #FF594D;
			}

			&.active::after {
				content: "";
				position: absolute;
				height: 2rpx;
				width: 375rpx;
				background-color: #FF594D;
				bottom: 0;
				left: 0;
			}
		}
	}

	.goods_nav {
		// #ifdef MP-WEIXIN
		// padding-bottom: 40rpx;
		background-color: #fff;
		// #endif
		z-index: 999999;
	}

	.example-body {
		padding: 0;
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
	}

	.goods-carts {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		position: fixed;
		left: 0;
		right: 0;
		/* #ifdef H5 */
		left: var(--window-left);
		right: var(--window-right);
		/* #endif */
		bottom: 0;
	}

	.indicator {
		@include flex(row);
		justify-content: center;

		&__dot {
			height: 6px;
			width: 6px;
			border-radius: 100px;
			background-color: rgba(0, 0, 0, 0.35);
			margin: 0 5px;
			transition: background-color 0.3s;

			&--active {
				background-color: #000;
			}
		}
	}

	.indicator-num {
		padding: 2px 0;
		background-color: rgba(0, 0, 0, 0.35);
		border-radius: 100px;
		width: 35px;
		@include flex;
		justify-content: center;

		&__text {
			color: #FFFFFF;
			font-size: 12px;
		}
	}

	.buy_list {
		position: absolute;
		bottom: 0;
		right: 0;

		.buy_item {
			width: 260rpx;
			height: 40rpx;
			color: #fff;
			line-height: 40rpx;
			font-size: 26rpx;
			background-color: rgba(0, 0, 0, 0.5);
			border-radius: 18rpx;
			padding-left: 20rpx;
			margin-bottom: 20rpx;
		}
	}

	.swiper_content {
		position: relative;

		.share {
			z-index: 1;
			position: absolute;
			right: 0;
			bottom: 0;

			button {
				background-color: transparent;
				padding: 0;
				border-radius: 0;

				&::after {
					border: 0;

				}
			}

			image {
				width: 134rpx;
				height: 88rpx;
				display: block;
			}
		}
	}

	.goods_price {
		height: 138rpx;
		border-radius: 20rpx 20rpx 0 0;
		background-color: #fff;
		box-sizing: border-box;
		padding: 18rpx 30rpx 20rpx;

		.price_top {
			display: flex;

			.left {
				margin-right: 50rpx;

				.current_price {
					font-size: 32rpx;
					display: flex;
					height: 45rpx;
					align-items: center;
					color: #FF2525;
					font-weight: bold;
					padding-right: 10rpx;

					text {
						font-size: 26rpx;
						font-weight: normal;
					}
				}

				.original_price {
					color: #777;
					text-decoration: line-through;
				}

				display: flex;

			}

			.tags {
				color: #FFA242;
				display: flex;

				.tag_item {
					padding: 6rpx 10rpx;
					font-size: 18rpx;
					white-space: nowrap;
					border-radius: 6rpx;
					background-color: #faf5eb;
					line-height: 38rpx;
					margin-right: 10rpx;
				}
			}
		}

		.goods_title {
			padding-top: 10rpx;
			font-size: 32rpx;
			color: #333332;
		}

	}

	.sponsor {
		padding: 0rpx 75rpx 50rpx;
		position: fixed;
		left: 0;
		box-sizing: border-box;
		width: 750rpx;
		bottom: 0;

		.sponsor_btn {
			width: 100%;
			height: 68rpx;
			border-radius: 44rpx;
			background: #FF594D;
			font-size: 24rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 66rpx;
		}
	}

	.goods_num {
		height: 325rpx;
		background: #faf5eb;
		border-radius: 6rpx 6rpx 6rpx 6rpx;
		box-sizing: border-box;
		padding: 20rpx;

		.goods_num_content {
			width: 710rpx;
			height: 275rpx;
			padding: 49rpx 78rpx;
			background-color: #fff;
			box-sizing: border-box;
			display: flex;

			.goods_img {
				width: 258rpx;
				height: 178rpx;
				border-radius: 10rpx 0 10rpx 0;
				overflow: hidden;
				border-right: 2rpx dashed #FFA242;

				image {
					width: 178rpx;
					height: 178rpx;
				}
			}

			.adjustment {
				padding-left: 80rpx;
				padding-top: 31rpx;

				.price {
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					color: #F44236;
					white-space: nowrap;

					text {
						color: #333332;
						font-size: 26rpx;
					}
				}

				.adjustment_num {
					display: flex;
					align-items: center;
					color: #333332;

					text {
						font-size: 32rpx;
						color: #F44236;
					}

					button {
						background-color: transparent;
						padding: 0;
						border: 0;
						color: #777777;
						font-size: 44rpx;

						&::after {
							border: 0;
						}
					}

					input {
						background-color: #FFA242;
						border-radius: 55rpx;
						width: 116rpx;
						height: 51rpx;
						text-align: center;
						padding: 0;
						margin: 0 10rpx;
						position: relative;
						z-index: 0;
						font-size: 24rpx;
					}
				}
			}
		}

	}

	.specification {
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FF594D;
		width: 750rpx;
		height: 69rpx;
		background: #FFFFFF;
		line-height: 69rpx;
		margin: 20rpx 0;
		padding-left: 20rpx;
	}

	.goods_detail_img {
		// padding-bottom: 150rpx;
		overflow: hidden;

		image {
			width: 750rpx;
			// height: 1027rpx;
			display: block;
		}
	}
</style>